package com.example.dao;

import com.example.domain.Candidate;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @author luo
 */
@Mapper
public interface CandidateDao {
    /**
     * 全部应聘者
     * @return
     */
    @Select("select * from candidate")
    public List<Candidate> selectCandidate();

    /**
     * 查询id应聘者
     * @param id
     * @return
     */
    @Select("select * from candidate where id=#{id}")
    public Candidate selectCandidateById(Integer id);

    //@Select("select * from candidate where name like CONCAT('%',#{username},'%');")
//    @SelectProvider(type = SqlBuilder.class, method = "selectSqlByName")
/*    @Select("<script>"
            +"select * from candidate"
            + "<where>"
            + "<if test='name !=null'> and name like CONCAT('%',#{name},'%')</if>"
            + "<if test='degree !=null'> and degree like CONCAT('%',#{degree},'%')</if>"
            + "<if test='experience !=null'> and experience like CONCAT('%',#{experience},'%')</if>"
            + "</where>"
            +"</script>")*/

    /**
     * 模糊查询
     * @param candidate
     * @return
     */
    public List<Candidate> selectCandidateByName(Candidate candidate);

    /**
     * 添加应聘者信息
     * @param candidate
     * @return
     */
    @Insert("insert into candidate (name, sex, age, phone, degree, experience, site) values (#{name}, #{sex}, #{age}, #{phone}, #{degree}, #{experience}, #{site})")
    public int addCandidate(Candidate candidate);

    /**
     * 更新应聘者信息
     *
     * @param candidate
     * @return
     */
    @Update("update candidate set name=#{name},sex=#{sex},age=#{age},phone=#{phone},degree=#{degree},experience=#{experience},site=#{site} where id=#{id};")
    public int updateCandidate(Candidate candidate);

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @Delete("delete from candidate where id=#{id};")
    public int deleteCandidate(Integer id);
}
